package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.UserService;
import com.example.demo.util.MybatisPlusUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserSerivceImpl  implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> userList(User user) {
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        MybatisPlusUtil.notNullField(user, userQueryWrapper);
        List<User> users = userMapper.selectList(userQueryWrapper);
        return users;
    }

    @Override
    public boolean addUser(User user) {
        int insert = userMapper.insert(user);
        return insert>0;
    }

    @Override
    public boolean updateUser(User user) {
        return userMapper.updateById(user)>0;
    }

    @Override
    public boolean delete(String id) {
        return userMapper.deleteById(id)>0;
    }
}
